Skip to content

feat: add streaming response support for ReActAgent and DeepAgent - #7

Merged
vearne merged 1 commit into
mainfrom
cursor/streaming-output-support
May 20, 2026
Merged

feat: add streaming response support for ReActAgent and DeepAgent#7
vearne merged 1 commit into
mainfrom
cursor/streaming-output-support

Conversation

@vearne

@vearne vearne commented May 20, 2026

Copy link
Copy Markdown
Owner
  • Add ReplyStream() method to ReActAgent and DeepAgent for progressive response streaming
  • Implement thinkAndActStream() internal method using model.Stream() API
  • Support tool calling, interruption, and tracing in streaming mode
  • Add comprehensive unit tests with mock streaming model
  • Create 5 example programs demonstrating various streaming scenarios:
    • agent_stream: basic streaming usage
    • stream_with_tools: streaming with tool integration
    • stream_comparison: performance comparison between streaming and non-streaming
    • interactive_stream: interactive CLI chat with streaming
    • deep_agent_stream: advanced DeepAgent features with streaming
  • Add complete documentation and usage guides

All tests pass with race detection enabled.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added streaming response capability to ReActAgent and DeepAgent for token-by-token incremental output
    • Streaming now supports tool calls and mid-stream interruption handling
    • Added interactive terminal-based chat example with real-time streaming responses
  • Documentation

    • Added comprehensive streaming implementation guide with 5 usage scenarios
    • Included performance comparisons, advanced configuration options, and FAQs

Review Change Stack

- Add ReplyStream() method to ReActAgent and DeepAgent for progressive response streaming
- Implement thinkAndActStream() internal method using model.Stream() API
- Support tool calling, interruption, and tracing in streaming mode
- Add comprehensive unit tests with mock streaming model
- Create 5 example programs demonstrating various streaming scenarios:
  * agent_stream: basic streaming usage
  * stream_with_tools: streaming with tool integration
  * stream_comparison: performance comparison between streaming and non-streaming
  * interactive_stream: interactive CLI chat with streaming
  * deep_agent_stream: advanced DeepAgent features with streaming
- Add complete documentation and usage guides

All tests pass with race detection enabled.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vearne
vearne merged commit c7fd6c6 into main May 20, 2026
1 check passed
@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 46125a1e-708a-4bdd-bae0-3e409b7c4111

📥 Commits

Reviewing files that changed from the base of the PR and between a93f30e and 232df3a.

📒 Files selected for processing (11)
  • STREAMING_IMPLEMENTATION_SUMMARY.md
  • examples/STREAMING_EXAMPLES.md
  • examples/agent_stream/main.go
  • examples/deep_agent_stream/main.go
  • examples/interactive_stream/main.go
  • examples/stream_comparison/main.go
  • examples/stream_with_tools/main.go
  • pkg/agent/deep.go
  • pkg/agent/deep_test.go
  • pkg/agent/react.go
  • pkg/agent/react_test.go

📝 Walkthrough

Walkthrough

AgentScope-Go streaming output implementation adds ReplyStream and thinkAndActStream methods to ReActAgent and DeepAgent, enabling real-time token-by-token response streaming over channels. Includes full test coverage, comprehensive documentation of the implementation and architecture, and five example programs demonstrating streaming across basic, tool-based, comparative, interactive, and advanced DeepAgent scenarios.

Changes

Core Streaming Implementation & Testing

Layer / File(s) Summary
ReActAgent streaming entrypoint and iteration
pkg/agent/react.go
ReplyStream runs agent loop in background and streams messages over a buffered channel; thinkAndActStream performs one iteration using model.Stream, forwarding partial messages and handling tool execution.
DeepAgent streaming entrypoint and iteration
pkg/agent/deep.go
ReplyStream mirrors non-streaming Reply control flow but returns buffered channel; thinkAndActStream performs one iteration using model.Stream, streaming assistant content with optional tool approval and output offloading.
ReActAgent streaming tests
pkg/agent/react_test.go
mockStreamModel enables streaming test harness; TestReActAgent_StreamSimpleReply validates incremental message emission and final content; TestReActAgent_StreamWithToolUse validates streaming through tool-use interaction.
DeepAgent streaming tests
pkg/agent/deep_test.go
TestDeepAgent_StreamSimpleReply validates streamed messages and memory size; TestDeepAgent_StreamWithToolUse validates streaming through tool-use with correct message count.
Implementation documentation
STREAMING_IMPLEMENTATION_SUMMARY.md
Comprehensive overview covering core capabilities, test coverage, example program catalog, usage patterns, performance characteristics, technical highlights, code quality metrics, and next steps.

Streaming Usage Examples & User Guide

Layer / File(s) Summary
Streaming user guide and quick start
examples/STREAMING_EXAMPLES.md
Introduction to streaming examples, setup/run instructions, streaming vs non-streaming control flow explanation, use case recommendations, performance comparison, advanced agent configuration options, FAQ, and related documentation links.
Basic and comparative streaming examples
examples/agent_stream/main.go, examples/stream_comparison/main.go
agent_stream demonstrates streaming from both ReActAgent and DeepAgent; stream_comparison runs non-streaming vs streaming side-by-side with elapsed time measurement.
Streaming with tool calls
examples/stream_with_tools/main.go
Demonstrates streaming agent replies with registered weather and time tools across three scenarios: single weather query, single time query, and combined multi-tool query.
Advanced DeepAgent streaming examples
examples/deep_agent_stream/main.go
Runs three demonstrations: basic DeepAgent response, DeepAgent with calculate tool, and context-compression scenario using TruncatingCompressor with max context token limits.
Interactive terminal streaming
examples/interactive_stream/main.go
Read-eval loop over stdin that streams assistant responses, supporting quit/exit and clear commands; includes per-session message counting and summary output.

Sequence Diagram

sequenceDiagram
  participant Client
  participant ReplyStream as ReplyStream<br/>(goroutine)
  participant thinkAndActStream
  participant Model
  participant Channel as Channel<br/>(buffered)
  Client->>ReplyStream: ReplyStream(ctx, msg)
  ReplyStream->>ReplyStream: setup memory & hooks
  ReplyStream->>ReplyStream: spawn background goroutine
  activate ReplyStream
  loop Agent Iterations
    ReplyStream->>thinkAndActStream: invoke
    activate thinkAndActStream
    thinkAndActStream->>Model: Stream()
    activate Model
    loop Streamed Chunks
      Model->>thinkAndActStream: ChatResponse chunk
      thinkAndActStream->>Channel: emit partial *message.Msg
    end
    Model->>thinkAndActStream: stream complete
    deactivate Model
    thinkAndActStream->>thinkAndActStream: persist final assistant msg
    alt Tool Use Detected
      thinkAndActStream->>thinkAndActStream: execute tools
      thinkAndActStream->>Channel: emit tool result msg
    end
    deactivate thinkAndActStream
  end
  ReplyStream->>Channel: close channel
  deactivate ReplyStream
  Client->>Channel: receive <-chan *message.Msg
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • vearne/agentscope-go#3: DeepAgent streaming implementation directly extends the core DeepAgent loop, memory management, compression, and tool handling introduced in this PR.
  • vearne/agentscope-go#4: Streaming implementations add mid-stream interruption handling that builds on the Interrupt/HandleInterrupt functionality from this PR.

Poem

🐰 Token by token, the stream flows free,
No more waiting for a full reply, you see!
From ReAct to Deep, now both can stream,
With tools and interrupts—a developer's dream!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/streaming-output-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vearne
vearne deleted the cursor/streaming-output-support branch May 20, 2026 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant